<?php

declare(strict_types=1);

/**
 * @Author:     Frank
 * @contact     frank_hhm@163.com
 * @Date:       2023-02-04 12:51:09
 * @Last Modified time: 2023-02-16 18:36:44
 */
namespace app\common\model\store;

use frank\base\BaseModel;
use frank\traits\ModelTrait;
use app\common\model\store\GoodsModel;

/**
 * 商品收藏
 * Class GoodsCollectionModel
 * @package app\common\model\store
 */
class GoodsCollectionModel extends BaseModel
{
	use ModelTrait;
    /**
     * 数据表主键
     */
    protected $pk = 'id';

    /**
     * 模型名称
     */
    protected $name = 'store_goods_collection';


    /**
     * 关联商品
     */
    public function goods(){
        return $this->hasOne(GoodsModel::class,'id','goods_id');
    }

    /**
     * userid搜索器
     */
    public function searchUserIdAttr($query, $value)
    {
        if (is_array($value)) {
            $query->whereIn('user_id', $value);
        } else {
            $query->where('user_id', $value);
        }
    }

    /**
     * goodsid搜索器
     */
    public function searchGoodsIdAttr($query, $value)
    {
        if (is_array($value)) {
            $query->whereIn('goods_id', $value);
        } else {
            $query->where('goods_id', $value);
        }
    }
}

